package com.example.demo0.Controller;

import com.example.demo0.entity.User;
import com.example.demo0.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController // Marks this class as a REST controller
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/users") // Exposes this method as a GET API endpoint
    public List<User> getAllUsers() {
        return userService.getAllUsers(); // Queries all users through the service layer
    }

    @GetMapping("/user-with-role") // Exposes this method as a GET API endpoint
    public User getUserWithRole(@RequestParam Long id) {
        return userService.getUserWithRoleById(id);
    }
}